import 'package:earclean/app/config/colors.dart';
import 'package:earclean/app/modules/widget/app_bar_widget.dart';
import 'package:earclean/app/routes/app_pages.dart';
import 'package:earclean/app/util/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import '../controllers/mine_controller.dart';

class MineView extends GetView<MineController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: const AppBarWidget(
          backgroundColor: ColorConfig.white,
          showLeading: false,
          titleStr: '我的'),
      backgroundColor: ColorConfig.bg_color,
      body: Column(
        children: [
          const SizedBox(height: 15),
          Container(
            margin: const EdgeInsets.symmetric(horizontal: 18),
            child: Row(
              children: [
                Image.asset(
                  'assets/images/组 35@2x.png',
                  width: 40,
                  height: 40,
                  fit: BoxFit.cover,
                ),
                const SizedBox(width: 10),
                Obx(() => Text(
                      controller.mobile.value,
                      style: TextStyle(
                          fontSize: 16.sp,
                          fontWeight: FontWeight.bold,
                          color: ColorConfig.text_label),
                    )),
              ],
            ),
          ),
          const SizedBox(height: 15),
          Container(
            margin: const EdgeInsets.symmetric(
              horizontal: 18,
            ),
            padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 10),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(10.r)),
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                GridView.builder(
                  physics: const NeverScrollableScrollPhysics(),
                  shrinkWrap: true,
                  gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                      childAspectRatio: 1,
                      crossAxisCount: 4,
                      crossAxisSpacing: 20.0,
                      mainAxisSpacing: 20.0),
                  itemBuilder: (BuildContext context, int index) {
                    Map item = controller.topdataList[index];
                    return InkWell(
                      onTap: () {
                        if (index == 0) {
                          Get.toNamed(Routes.WEB, arguments: {
                            "title": '订单',
                            "url": box.read('my_need_url'),
                          });
                        } else {
                          Get.toNamed(Routes.WEB, arguments: {
                            "title": '钱包',
                            "url": box.read('my_account'),
                          });
                        }
                        // controller.goOrder();
                      },
                      child: Column(
                        children: [
                          Image.asset(
                            item['img'],
                            height: 35,
                            fit: BoxFit.cover,
                          ),
                          const SizedBox(height: 5),
                          Text(item['name'],
                              style: const TextStyle(
                                  fontSize: 13, color: ColorConfig.text_label)),
                        ],
                      ),
                    );
                  },
                  itemCount: controller.topdataList.length,
                )
              ],
            ),
          ),
          const SizedBox(height: 15),
          Container(
            margin: const EdgeInsets.symmetric(horizontal: 18),
            padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 10),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(10.r)),
            ),
            child: GridView.builder(
              physics: const NeverScrollableScrollPhysics(),
              shrinkWrap: true,
              gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                  childAspectRatio: 1,
                  crossAxisCount: 4,
                  crossAxisSpacing: 20.0,
                  mainAxisSpacing: 20.0),
              itemBuilder: (BuildContext context, int index) {
                Map item = controller.dataList[index];
                return InkWell(
                  onTap: () {
                    controller.clickIten(index);
                  },
                  child: Column(
                    children: [
                      Expanded(
                        child: Image.asset(
                          item['img'],
                          height: 35,
                          fit: BoxFit.cover,
                        ),
                      ),
                      const SizedBox(height: 5),
                      Text(item['name'],
                          style: const TextStyle(
                              fontSize: 13, color: ColorConfig.text_label)),
                    ],
                  ),
                );
              },
              itemCount: controller.dataList.length,
            ),
          ),
        ],
      ),
    );
  }
}
